package com.lzx.httpclient;

import java.io.OutputStream;

public class StringBody extends AbstractBody {

	private String name;

	private String value;

	public StringBody(String name, String value) {
		this.name = name;
		this.value = value;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public void writeTo(OutputStream os, boolean writeContent) {
		try{
			
			
			
//			-----------------------------98942870323811
//			Content-Disposition: form-data; name="name"
//				
//			1 
		StringBuilder sb = new StringBuilder();
		sb.append("--" + this.boundary + LR);		
		sb.append("Content-Disposition: form-data; name=\"" + this.name + "\"" + LR);
		sb.append(LR);
		
		if(writeContent) {
			sb.append(this.value+LR);
		}
		
		os.write(sb.toString().getBytes());
		System.out.print(sb);
	
		} catch (Exception e) {
			// TODO: handle exception
		}		
	}

	@Override
	public long getContentLength() {
		// TODO Auto-generated method stub
		return this.value.getBytes().length;
	}

}
